﻿import pygame
from pygame import Rect
from pygame.locals import *
from sys import exit
 
AMERICA_DO_SUL_X = 0 
AMERICA_DO_SUL_Y = 0 

OCEANIA_X = 0 
OCEANIA_Y = 0 

AFRICA_X = 0 
AFRICA_Y = 0 

AMERICA_DO_NORTE_X = 0
AMERICA_DO_NORTE_Y = 0

EUROPA_X = 0
EUROPA_Y = 0

AMERICA_DO_SUL = 1
OCEANIA = 2
AFRICA = 3
AMERICA_DO_NORTE = 4
EUROPA = 5

COUNTRIES = {}
COUNTRIES['venezuela'] = [AMERICA_DO_SUL, (10, 0)]
COUNTRIES['bolivia'] = [AMERICA_DO_SUL, (0, 51)]
COUNTRIES['brasil'] = [AMERICA_DO_SUL, (32, 33)]
COUNTRIES['argentina'] = [AMERICA_DO_SUL, (59, 147)]

COUNTRIES['sumatra'] = [OCEANIA, (0, 30)]
COUNTRIES['borneo'] = [OCEANIA, (60, 0)]
COUNTRIES['nova_guine'] = [OCEANIA, (151, 29)]
COUNTRIES['australia'] = [OCEANIA, (64, 77)]

COUNTRIES['argelia'] = [AFRICA, (0, 0)]
COUNTRIES['egito'] = [AFRICA, (109, 19)]
COUNTRIES['sudao'] = [AFRICA, (126, 65)]
COUNTRIES['congo'] = [AFRICA, (107, 148)]
COUNTRIES['africa_do_sul'] = [AFRICA, (119, 223)]
COUNTRIES['madagascar'] = [AFRICA, (244, 232)]

COUNTRIES['alaska'] = [AMERICA_DO_NORTE, (1, 63)]
COUNTRIES['mackenzie'] = [AMERICA_DO_NORTE, (91, 61)]
COUNTRIES['vancouver'] = [AMERICA_DO_NORTE, (94, 110)]
COUNTRIES['ottawa'] = [AMERICA_DO_NORTE, (206, 121)]
COUNTRIES['labrador'] = [AMERICA_DO_NORTE, (268, 98)]
COUNTRIES['california'] = [AMERICA_DO_NORTE, (75, 151)]
COUNTRIES['nova_york'] = [AMERICA_DO_NORTE, (145, 165)]
COUNTRIES['mexico'] = [AMERICA_DO_NORTE, (86, 233)]
COUNTRIES['groenlandia'] = [AMERICA_DO_NORTE, (359, 0)]

COUNTRIES['inglaterra'] = [EUROPA, (20, 31)]
COUNTRIES['islandia'] = [EUROPA, (0, 6)]
COUNTRIES['franca'] = [EUROPA, (41, 83)]
COUNTRIES['alemanha'] = [EUROPA, (90, 54)]
COUNTRIES['polonia'] = [EUROPA, (120, 67)]
COUNTRIES['moscou'] = [EUROPA, (150, 4)]
COUNTRIES['suecia'] = [EUROPA, (99, 0)]


def load(continent, countries):
    images = {}
    positions = {}
    for p in countries :
        images[p] = pygame.image.load('images/'+continent+'/'+p+'.png').convert_alpha()
        positions[p] = {'x':0, 'y':0}
    
    return images, positions
    
def paint(screen,countries,images,positions) :
    for p in countries :
        screen.blit(images[p],(positions[p]['x'], positions[p]['y']))
 
def main() :
    pygame.init()
    screen = pygame.display.set_mode((512,512), 0, 32)
    pygame.display.set_caption('War')

    background_image = pygame.image.load('images/background.png').convert()    
    
    continent = 'europa'
    countries = ['inglaterra','islandia','franca','alemanha','polonia','moscou','suecia']
    images, positions = load(continent, countries)
    
    INC = 1
    
    f = open('file.txt', 'w')
    
    #clock = pygame.time.Clock()

    while True :

        for event in pygame.event.get() :
            if event.type == QUIT :
                f.close()
                exit(0)
            if event.type == KEYDOWN and event.key == K_ESCAPE:
                f.close()
                exit(0)
            if event.type == KEYDOWN and event.key == K_RETURN:
                for p in countries :
                    x, y = positions[p]['x'], positions[p]['y']
                    f.write('COUNTRIES[\''+p+'\'] = ['+continent.upper()+', ('+str(x)+', '+str(y)+')]\n')
                f.write('-'*10)
            if event.type == KEYDOWN :
                if event.key == K_UP :
                    positions[country]['y'] -= INC
                elif event.key == K_DOWN :
                    positions[country]['y'] += INC
                elif event.key == K_LEFT :
                    positions[country]['x'] -= INC
                elif event.key == K_RIGHT :
                    positions[country]['x'] += INC
                elif event.key == K_0 :
                    country = raw_input('País::').lower()
                elif event.key == K_1 :
                    INC = 1
                elif event.key == K_2 :
                    INC = 10
                elif event.key == K_3 :
                    INC = 50                  
                    
                
        #time_passed = clock.tick(FPS)
        screen.blit(background_image,(0,0))
        paint(screen, countries, images, positions)
        
        pygame.display.update()
        
if __name__ == '__main__' :
    main()